package core

class GovernorateController {
	static layout = 'country'

    def createGov()
	{
			
	}
	def update() {
		def governorate =  Governorate.get(params.long('id'))
		governorate.properties = params
		if(governorate.save()) {
			flash.notice = "Governorate: ${governorate.name} was updated"
			redirect action:'index'
		}
		else {
			flash.error = "Governorate:  failed to be update"
			render(view:'editGov',model:[governorate: governorate])
		}
	}
	
	def editGov()
	{
		[governorate: Governorate.get(params.long('id'))]	
	}
	
	def deleteGov()
	{
	def governorate =  Governorate.get(params.id)
	   
		governorate.delete()
		redirect(action:'index')	
	}
	
	def save() {
		def governorate = new Governorate(params)
		
		if (governorate.save()) {
			flash.notice = "Governorate ${governorate.name}: is saved successfuly"
			redirect(action:'index')
		} else {
			flash.error = "Governorate ${governorate.name}: Failed to save"
			render view:'createGov', model:[governorate:governorate]
		}
	}

    def index() { 
		
		def max = params.long('max')?:10
		def start = params.long('start')?:0
		[governorates:Governorate.list(max: max, offset:start ),max:max, start:start ]
		
		
	}
	

	
	def show() {
		
				[governorates: Governorate.get(params.long('id'))]
			}
}
